<template>
    <div>   
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员等级</td>
                    <td>
                        <input type="text" v-model="queryInfo.levelName">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{ref,reactive}from 'vue'
import axios from 'axios';
import {useRouter} from 'vue-router'
import router from '@/router';


let queryInfo=reactive({
    levelName:'',
})

const add=()=>{

    if(queryInfo.levelName==""){
        alert("会员等级不能为空");
        return;
    }

    axios({
        method:'post',
        url:'/api/Member/MemberAdd',
        data:queryInfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert("会员等级已存在");
            return;
        }
        else if(res.data>0){
            alert("添加成功");
            router.push('/levelshow');
            return;
        }
        else{
            alert("添加失败");
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
}


</script>

<style scoped>

</style>